package com.sky.controller.admin;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.dto.CategoryDTO;
import com.sky.pojo.Category;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import com.sky.vo.CategoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description CategoryController
 * @Author shejunlian
 * @Date 2024-07-22
 */

@RestController
@RequestMapping("/admin/category")
@Api(tags = "分页管理")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     *
     * @param categoryDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增分类")
    public Result<String> addClassify(@RequestBody CategoryDTO categoryDTO) {
        log.info("处理请求新增分类的参数:{}", categoryDTO);
        categoryService.addClassify(categoryDTO);
        return Result.success();
    }

    /**
     * 分类分页查询
     *
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> pageClassify(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("处理请求分类分页查询参数:{}", categoryPageQueryDTO);
        PageResult pageResult = categoryService.pageClassify(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除分类
     *
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("根据id删除分类")
    public Result deleteClassify(Long id) {
        log.info("处理请求根据id删除分类的参数:{}", id);
        categoryService.deleteClassify(id);
        return Result.success();

    }

    /**
     * 修改分页
     *
     * @param categoryDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改分类")
    public Result<String> updateClassify(@RequestBody CategoryDTO categoryDTO) {
        log.info("处理请求参数修改分类的参数: {}", categoryDTO);
        categoryService.updateClassify(categoryDTO);
        return Result.success();
    }

    /**
     * 启用禁用分类
     *
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用分类")
    public Result<String> statusClassify(@PathVariable Integer status, Long id) {
        log.info("处理请求启用禁用分类的参数: {},{}", status, id);
        categoryService.statusClassify(status, id);
        return Result.success();

    }

    /**
     * 根据类型查询分类
     * @param type
     * @return
     */
    @GetMapping("list")
    @ApiOperation("根据类型查询分类")
    public Result<List<CategoryVo>> insertClassify(Integer type) {
        log.info("处理请求根据类型查询分类的参数: {}", type);
        List<CategoryVo> voList = categoryService.insertClassify(type);
        return Result.success(voList);

    }
}
